package algorithm.sort;

/**
 * @Author liuhaoqi
 * @Date 2020/12/19 15:51
 * @Version 1.0
 * 选择排序
 */
public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {1, 2, 6, 7, 8, 9, 9, 1, 7};
        int[] arrs = selectionSort(arr);
        for (int i : arrs) {
            System.out.println(i);
        }
    }
    public static int[] selectionSort(int[] array) {
        int n = array.length;
        if (n == 0) {
            return array;
        }
        for (int i = 0; i < n; i++) {
            int minIndex = i;
            for (int j = i; j < n; j++) {
                if (array[j] < array[minIndex]) {
                    minIndex = j;
                }
            }
            int temp = array[i];
            array[i] = array[minIndex];
            array[minIndex] = temp;
        }
        return array;
    }
}
